import sys
from app import Application
import logging
import scavenger

if __name__ == "__main__":
    # Set up logging.
    if '-d' in sys.argv:
        logging.basicConfig(level=logging.DEBUG,
                            format='%(asctime)s - %(levelname)s: %(message)s\n'\
                                   '\t%(filename)s, %(funcName)s, %(lineno)s',
                            datefmt='%m/%d/%y %H:%M:%S')
    else:
        logging.basicConfig(level=logging.ERROR,
                            format='%(asctime)s - %(levelname)s: %(message)s',
                            datefmt='%m/%d/%y %H:%M:%S')
    
    # Start the application.
    try:
        app = Application(sys.argv)
    except Exception, e:
        logging.getLogger('Main').error('Exception raised in main thread.', exc_info=True)
        sys.exit(1)
            
    rc = app.run()
    scavenger.shutdown()
    sys.exit(rc)
    
